import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:school_assistant_m/app/routes/app_pages.dart';
import 'package:school_assistant_m/widgets/full_width_button_widget.dart';

import '../controllers/mine_controller.dart';

class MineView extends GetView<MineController> {
  Widget _getHeaderView() {
    return GetBuilder<MineController>(
      id: 'userInfo',
      init: controller, // 首次启动
      builder: (_) => Container(
        color: Colors.white,
        padding: EdgeInsets.symmetric(vertical: 13.0, horizontal: 20.0),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            SizedBox(
              width: 60,
              height: 60,
              child: ClipRRect(
                borderRadius: BorderRadius.circular(10),
                child: Image.asset('assets/images/background.jpg',)
              ),
            ),
            SizedBox(width: 10.0),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Text(
                    controller.realName,
                    style: TextStyle(
                      color: Colors.black87,
                      fontSize: 16.0,
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                  SizedBox(height: 10.0),
                  Text(
                    '班级: ${controller.grade} 性别: ${controller.sex}',
                    style: TextStyle(
                      color: Colors.grey,
                      fontSize: 13.0,
                    ),
                  ),
                  SizedBox(height: 10.0),
                  Text(
                    '身份: ${controller.role} 学号: ${controller.userName}',
                    style: TextStyle(
                      color: Colors.grey,
                      fontSize: 13.0,
                    ),
                  )
                ],
              ),
            ),
            Icon(
              Icons.qr_code,
              size: 22.0,
              color: Colors.grey,
            ),
            SizedBox(width: 5.0),
            Icon(
              Icons.arrow_forward_ios,
              color: Colors.grey,
              size: 18.0,
            ),
          ],
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        height: Get.height,
        color: Color(0xffebebeb),
        child: SingleChildScrollView(
          child: Column(
            children: <Widget>[
              SizedBox(height: 55.0),
              _getHeaderView(),
              SizedBox(height: 20.0),
              FullWidthButton(
                iconPath: 'assets/images/setting.jpg',
                title: '设置',
                onPressed: () {
                  Get.toNamed(Routes.SETTINGS);
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}
